package com.zhouyu.gamecommunity.entity;

import com.zhouyu.gamecommunity.contants.ResultCode;
import lombok.Data;

/**
 * 分页返回结果
 */
@Data
public class PageResult<T> extends Result<T> {
    // 当前页码
    private Long pageNum;
    
    // 每页数量
    private Long pageSize;
    
    // 总记录数
    private Long total;
    
    // 总页数
    private Long pages;
    
    public static <T> PageResult<T> success(T data, Long pageNum, Long pageSize, Long total) {
        PageResult<T> result = new PageResult<>();
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMessage(ResultCode.SUCCESS.getMessage());
        result.setData(data);
        result.setPageNum(pageNum);
        result.setPageSize(pageSize);
        result.setTotal(total);
        result.setPages((total + pageSize - 1) / pageSize);
        return result;
    }
}